using UnityEngine;
using UnityEngine.UI;

namespace IQIGame.Onigao.Framework
{
    [AddComponentMenu("UIEx/ExImage", 14)]
    public class ExImage : Image, IUGUIEx
    {
        /// <summary>
        /// 是否自动国际化
        /// </summary>
        [SerializeField]
        private bool _isAutoI18N;
        /// <summary>
        /// 可切换的预设图片列表，可用作类似品质框的功能里，注意其中所有图片都必须属于同一个图集
        /// </summary>
        [SerializeField]
        private Sprite[] _switchSprites;

        public bool isAutoI18N
        {
            set { _isAutoI18N = value; }
            get { return _isAutoI18N; }
        }
        public object dynamicData { get; set; }

        public void SetActive(bool isActive)
        {
            this.gameObject.SetActive(isActive);
        }

        #region URP ScrollView裁剪范围更新
        public override void SetClipRect(Rect clipRect, bool validRect)
        {
            base.SetClipRect(clipRect, validRect);
            if (material == defaultMaterial) return;
            var clip = new Vector4(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
            material.SetVector(UICoreHelper.UIClipRect, clip);
        }

        public override void SetClipSoftness(Vector2 clipSoftness)
        {
            base.SetClipSoftness(clipSoftness);
            if (material == defaultMaterial) return;

            var softness = new Vector4(clipSoftness.x, clipSoftness.y, 0, 0);
            material.SetVector(UICoreHelper.UIClipSoftnessRect, softness);
        }
        #endregion
    }
}
